/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package action;

import java.io.*;
import java.net.*;

import java.util.List;
import javax.servlet.*;
import javax.servlet.http.*;
import negocio.TicketManager;
import persistencia.pojo.Ticket;
import persistencia.pojo.Usuario;

/**
 *
 * @author Victor
 */
public class VerTicketAsignadosAction extends HttpServlet {
   
    /** 
    * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
    * @param request servlet request
    * @param response servlet response
    */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        String co_soporte="";
        String filasResul="";
        try {
            HttpSession session = request.getSession(true);
            Usuario usr= (Usuario)session.getAttribute("usuario");
            co_soporte= usr.getCodigo();
            TicketManager mgr = new  TicketManager();
            List<Ticket> listadoTickets = mgr.getTicketsAsignadoSoporte(co_soporte);
              
            for(int i=0; i<listadoTickets.size(); i++){
                filasResul+= filaResultado(listadoTickets.get(i).getCodigo(), listadoTickets.get(i).getCo_operador(), listadoTickets.get(i).getTipo_ticket(), listadoTickets.get(i).getDesc_ticket());
            }
            
            Dibujatabla(response, filasResul);             
        
        }catch (Exception e) {
            e.printStackTrace();
        }
    } 
    private void mensaje(HttpServletResponse response, String mensaje) throws ServletException, IOException{
        PrintWriter out = response.getWriter();
        try {

            out.println(mensaje);
            out.flush();
        } finally { 
            out.close();
        }
    }
    
    private void Dibujatabla(HttpServletResponse response, String strFilasResul) throws ServletException, IOException{
        PrintWriter out = response.getWriter();
        try {
            String strTabla = "<table width=\"725\" border=\"3\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">";
            strTabla+="  <tr>";
            strTabla+="    <td width=\"115\" bgcolor=\"#81BEF7\" class=\"Estilo12\" height=\"30\"><div align=\"center\">Codigo Ticket</div></td>";
            strTabla+="    <td width=\"115\" bgcolor=\"#81BEF7\" class=\"Estilo12\"><div align=\"center\">Operador</div></td>";
            strTabla+="    <td width=\"115\" bgcolor=\"#81BEF7\" class=\"Estilo12\"><div align=\"center\">Tipo</div></td>";
            strTabla+="    <td width=\"352\" bgcolor=\"#81BEF7\" class=\"Estilo12\"><div align=\"center\">Descripcion</div></td>";
            strTabla+="  </tr>";
            strTabla+=strFilasResul;
            strTabla+="</table>";

            out.println(strTabla);
            out.flush();
        } finally { 
            out.close();
        }
    }
    private String filaResultado(String co_ticket, String co_operador, String tipo_ticket, String desc_ticket){
        String fila= "<tr class=\"Estilo6\" onMouseOver=\"overTR(this);\" onMouseOut=\"outTR(this);\" onClick=\"clickTR('"+co_ticket+"');\">";
	fila+="<td height=\"20\">"+co_ticket+"</td>";
	fila+="<td>"+co_operador+"</td>";
	fila+="<td>"+tipo_ticket+"</td>";
	fila+="<td>"+desc_ticket+"</td>";
	fila+="</tr>";
        
        return fila;
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
    * Handles the HTTP <code>GET</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

    /** 
    * Handles the HTTP <code>POST</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
    * Returns a short description of the servlet.
    */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
}
